<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>旅游线路 - 汉中旅游</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="css/style.css">
    <script src="js/api.js" defer></script>
    <style>
        /* 页面基础样式 */
        .page-header {
            background: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('img/attractions/hanzhongfengguang.jpg');
            background-size: cover;
            background-position: center;
            color: white;
            text-align: center;
            padding: 100px 0;
        }
        
        .page-header h1 {
            font-size: 36px;
            margin-bottom: 20px;
        }
        
        .page-header p {
            font-size: 18px;
            margin: 0 auto;
        }

        /* 分类导航样式 */
        .category-nav {
            display: flex;
            justify-content: center;
            gap: 30px;
            margin: 40px 0;
        }
        
        .category-link {
            text-decoration: none;
            color: #333;
            text-align: center;
            transition: all 0.3s;
        }
        
        .category-link:hover {
            transform: translateY(-5px);
        }
        
        .category-icon {
            width: 80px;
            height: 80px;
            background-color: #e74c3c;
            color: white;
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            margin: 0 auto 10px;
            font-size: 30px;
            transition: all 0.3s;
        }
        
        .category-link:hover .category-icon {
            background-color: #c0392b;
        }

        /* 路线卡片样式 */
        .route-detail {
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
            margin-bottom: 40px;
            overflow: hidden;
        }
        
        .route-header {
            background-color: #e74c3c;
            color: white;
            padding: 15px 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .route-header h3 {
            margin: 0;
            font-size: 22px;
        }
        
        .route-tag {
            background-color: rgba(255, 255, 255, 0.2);
            padding: 5px 10px;
            border-radius: 4px;
            font-size: 14px;
        }
        
        .route-image {
            width: 100%;
            height: 300px;
            overflow: hidden;
        }
        
        .route-image img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: transform 0.3s;
        }
        
        .route-detail:hover .route-image img {
            transform: scale(1.05);
        }
        
        .route-content {
            padding: 20px;
        }
        
        .route-info {
            margin-bottom: 20px;
        }

        /* 行程时间轴样式 */
        .route-schedule {
            list-style-type: none;
            padding: 0;
            margin: 20px 0;
            border-left: 2px solid #e74c3c;
        }
        
        .route-schedule li {
            display: flex;
            margin-bottom: 20px;
            padding-left: 20px;
            position: relative;
        }
        
        .route-schedule li:before {
            content: '';
            width: 12px;
            height: 12px;
            background-color: #e74c3c;
            border-radius: 50%;
            position: absolute;
            left: -6px;
            top: 5px;
        }
        
        .time {
            min-width: 80px;
            font-weight: bold;
            color: #e74c3c;
        }
        
        .schedule-content {
            flex: 1;
        }
        
        .schedule-content h4, .schedule-content h5 {
            margin: 0 0 5px 0;
        }
        
        .schedule-content p {
            margin: 0;
            color: #666;
        }

        /* 提示和加载状态样式 */
        .route-tips {
            background-color: #f9f9f9;
            padding: 15px;
            border-radius: 4px;
            margin-bottom: 20px;
        }
        
        .route-tips h4 {
            margin-top: 0;
            color: #e74c3c;
        }
        
        .route-tips ul {
            padding-left: 20px;
            margin: 10px 0;
        }

        .loading-placeholder {
            text-align: center;
            padding: 40px;
            background: #f9f9f9;
            border-radius: 8px;
            margin: 20px 0;
        }
        
        .loading-placeholder i {
            font-size: 32px;
            color: #e74c3c;
            margin-bottom: 15px;
            display: block;
        }
        
        .loading-placeholder p {
            color: #666;
            margin: 0;
            font-size: 16px;
        }
        
        .api-error {
            text-align: center;
            padding: 20px;
            color: #e74c3c;
            background-color: #fde9e8;
            border-radius: 4px;
            margin: 20px 0;
        }
        
        .api-error i {
            margin-right: 10px;
            font-size: 20px;
        }

        /* 响应式调整 */
        @media (max-width: 768px) {
            .route-image {
                height: 200px;
            }
            
            .route-schedule li {
                flex-direction: column;
            }
            
            .time {
                margin-bottom: 5px;
            }
            
            .category-icon {
                width: 60px;
                height: 60px;
                font-size: 24px;
            }
        }

        /* 添加缺失的样式 */
        .route-booking {
            background-color: #f9f9f9;
            padding: 20px;
            border-radius: 4px;
            text-align: center;
            margin-top: 20px;
        }
        
        .route-booking h4 {
            color: #e74c3c;
            margin-bottom: 15px;
        }
        
        .route-booking .btn {
            display: inline-block;
            background-color: #e74c3c;
            color: white;
            padding: 10px 20px;
            border-radius: 4px;
            text-decoration: none;
            margin-top: 15px;
            transition: background-color 0.3s;
        }
        
        .route-booking .btn:hover {
            background-color: #c0392b;
        }
        
        .section-padding {
            padding-top: 40px;
            padding-bottom: 40px;
        }
        
        .routes-container {
            margin-bottom: 30px;
        }
    </style>
</head>
<body>
    <!-- 页面加载动画 -->
    <div class="page-loader">
        <div class="loader"></div>
    </div>

    <!-- 用户小部件 -->
    <div class="user-widget">
        <a href="login.html" id="login-link" class="btn btn-login">登录/注册</a>
        <div id="user-profile" style="display: none;">
            <img src="img/attractions/touxiang.jpg" alt="User Avatar" class="avatar">
            <span id="username-display"></span>
            <a href="#" id="logout-link" title="退出登录"><i class="fas fa-sign-out-alt"></i></a>
        </div>
    </div>

    <!-- 浮动导航菜单 -->
    <div class="float-nav">
        <button class="float-nav-toggle" id="floatNavToggle" title="快速导航">
            <i class="fas fa-bars"></i>
        </button>
        <div class="float-nav-menu" id="floatNavMenu">
            <ul>
                <li><a href="index.html">首页</a></li>
                <li><a href="jingdian.html">景点介绍</a></li>
                <li><a href="luxian.html" class="active">旅游线路</a></li>
                <li><a href="gonglue.html">旅游攻略</a></li>
                <li><a href="meishi.html">美食推荐</a></li>
                <li><a href="wenhua.html">汉文化活动</a></li>
                <li><a href="contact.html">联系我们</a></li>
                <li><a href="faq.html">常见问题</a></li>
            </ul>
        </div>
    </div>

    <!-- 导航栏 -->
    <nav>
        <div class="container">
            <div class="nav-container">
                <div class="nav-logo">
                    <a href="index.html">
                        <img src="img/attractions/logo.jpg" alt="汉中旅游" class="nav-logo-img">
                        <h2>汉中旅游</h2>
                    </a>
                </div>
                <ul class="main-nav">
                    <li><a href="index.html">首页</a></li>
                    <li><a href="jingdian.html">景点介绍</a></li>
                    <li><a href="luxian.html" class="active">旅游线路</a></li>
                    <li><a href="gonglue.html">旅游攻略</a></li>
                    <li><a href="meishi.html">美食推荐</a></li>
                    <li><a href="wenhua.html">汉文化活动</a></li>
                    <li><a href="contact.html">联系我们</a></li>
                    <li><a href="faq.html">常见问题</a></li>
                </ul>
                <!-- 用户操作区域已被移到独立的 user-widget 中 -->
            </div>
        </div>
    </nav>
    
    <!-- 主要内容 -->
    <main>
        <!-- 页面标题 -->
        <section class="page-header">
            <div class="container">
                <h1>汉中旅游线路</h1>
                <p>精心设计的旅游路线，让您深度体验汉中的自然与人文之美</p>
            </div>
        </section>

        <!-- 线路分类导航 -->
        <section class="container">
            <div class="category-nav">
                <a href="#oneday" class="category-link">
                    <div class="category-icon"><i class="fas fa-sun"></i></div>
                    <span>一日游</span>
                </a>
                <a href="#threedays" class="category-link">
                    <div class="category-icon"><i class="fas fa-calendar-day"></i></div>
                    <span>三日游</span>
                </a>
                <a href="#fivedays" class="category-link">
                    <div class="category-icon"><i class="fas fa-calendar-week"></i></div>
                    <span>五日游</span>
                </a>
            </div>
        </section>

        <!-- 一日游线路 -->
        <section id="oneday" class="container section-padding">
            <h2 class="section-title">汉中一日游线路</h2>
            <div id="oneday-routes" class="routes-container">
                <div class="loading-placeholder">
                    <i class="fas fa-spinner fa-spin"></i>
                    <p>正在加载一日游线路...</p>
                </div>
            </div>
        </section>

        <!-- 三日游线路 -->
        <section id="threedays" class="container section-padding">
            <h2 class="section-title">汉中三日游线路</h2>
            <div id="threeday-routes" class="routes-container">
                <div class="loading-placeholder">
                    <i class="fas fa-spinner fa-spin"></i>
                    <p>正在加载三日游线路...</p>
                </div>
            </div>
        </section>

        <!-- 五日游线路 -->
        <section id="fivedays" class="container section-padding">
            <h2 class="section-title">汉中五日游线路</h2>
            <div id="fiveday-routes" class="routes-container">
                <div class="loading-placeholder">
                    <i class="fas fa-spinner fa-spin"></i>
                    <p>正在加载五日游线路...</p>
                </div>
            </div>
        </section>
    </main>

    <!-- 页脚 -->
    <footer>
        <div class="container">
            <div class="footer-content">
                <div class="footer-section">
                    <h3>关于我们</h3>
                    <p>汉中旅游网致力于为游客提供最全面的汉中旅游信息，让您的汉中之行更加便捷、愉快。</p>
                    <div class="social-links">
                        <a href="#"><i class="fab fa-weibo"></i></a>
                        <a href="#"><i class="fab fa-weixin"></i></a>
                        <a href="#"><i class="fab fa-qq"></i></a>
                    </div>
                </div>
                <div class="footer-section">
                    <h3>快速链接</h3>
                    <ul>
                        <li><a href="index.html">首页</a></li>
                        <li><a href="jingdian.html">景点介绍</a></li>
                        <li><a href="luxian.html">旅游线路</a></li>
                        <li><a href="gonglue.html">旅游攻略</a></li>
                        <li><a href="contact.html">联系我们</a></li>
                    </ul>
                </div>
                <div class="footer-section">
                    <h3>热门景点</h3>
                    <ul>
                        <li><a href="jingdian.html#wuhoumu">武侯墓</a></li>
                        <li><a href="jingdian.html#nanhu">南湖</a></li>
                        <li><a href="jingdian.html#dingjunshan">定军山</a></li>
                        <li><a href="jingdian.html#guchengqiang">古城墙</a></li>
                    </ul>
                </div>
                <div class="footer-section">
                    <h3>联系方式</h3>
                    <p><i class="fas fa-map-marker-alt"></i> 地址：陕西省汉中市</p>
                    <p><i class="fas fa-phone"></i> 电话：0916-123456</p>
                    <p><i class="fas fa-envelope"></i> 邮箱：info@hanzhong-tourism.com</p>
                </div>
            </div>
        </div>
        <div class="footer-bottom">
            <div class="container">
                <p>&copy; 2023 汉中旅游网 版权所有</p>
            </div>
        </div>
    </footer>

    <script src="js/main.js"></script>
    <script src="js/script.js"></script>
    <script>
        // 渲染旅游线路数据
        function renderRouteDetail(routes, containerId) {
            const container = document.getElementById(containerId);
            if (!container) {
                console.error('找不到容器:', containerId);
                return;
            }

            if (!routes || routes.length === 0) {
                container.innerHTML = '<p style="text-align: center; padding: 20px;">暂无相关线路信息。</p>';
                return;
            }

            let allRoutesHtml = '';
            routes.forEach(route => {
                let scheduleHtml = '';

                if (route.days && route.days.length > 0) {
                    scheduleHtml = route.days.map(day => {
                        const activitiesHtml = day.activities.map(activity => {
                            return `
                                <li>
                                    <span class="time">${activity.time}</span>
                                    <div class="schedule-content">
                                        <h4>${activity.title}</h4>
                                        ${activity.description ? `<p>${activity.description}</p>` : ''}
                                    </div>
                                </li>
                            `;
                        }).join('');

                        // If a day consists of a single "DAILY_SUMMARY", its own time label (e.g., "第一天")
                        // is a better title than the generic "第X天".
                        const isSingleDailySummary = day.activities.length === 1 && day.activities[0].timeType === 'DAILY_SUMMARY';
                        const dayTitle = (route.days.length > 1 && !isSingleDailySummary) ? `<h4>第${day.dayNumber}天</h4>` : '';

                        return `
                            <div class="day-schedule">
                                ${dayTitle}
                                <ol class="route-schedule">${activitiesHtml}</ol>
                            </div>
                        `;
                    }).join('');
                }

                const tipsHtml = route.tips ?
                    route.tips.split('；').filter(t => t.trim() !== '').map(tip => `<li>${tip}</li>`).join('') :
                    '<li>暂无提示</li>';

                allRoutesHtml += `
                <div class="route-detail">
                    <div class="route-header">
                        <h3>${route.name || '汉中特色旅游路线'}</h3>
                        <span class="route-tag">${route.theme || '推荐路线'}</span>
                    </div>
                    <div class="route-image">
                        <img src="${route.image || 'img/attractions/default.jpg'}" alt="${route.name}">
                    </div>
                    <div class="route-content">
                        <div class="route-info">
                                <p><strong>路线特点：</strong> ${route.features || route.description || ''}</p>
                                <p><strong>适合人群：</strong> ${route.suitableFor || '所有游客'}</p>
                            <p><strong>交通方式：</strong> ${route.transportation || '自由行'}</p>
                            <p><strong>价格：</strong> ¥${route.price || '待定'}</p>
                            <p><strong>行程安排：</strong></p>
                                ${scheduleHtml || '<p>暂无详细行程</p>'}
                            </div>
                            <div class="route-tips">
                                <h4><i class="fas fa-lightbulb"></i> 贴心提示</h4>
                                <ul>${tipsHtml}</ul>
                        </div>
                        <div class="route-booking">
                            <h4>预订咨询</h4>
                            <p>如需预订此线路或定制专属行程，请联系我们：</p>
                            <p><i class="fas fa-phone"></i> 电话：18165245563</p>
                            <p><i class="fas fa-envelope"></i> 邮箱：1959847182@qq.com</p>
                            <a href="contact.html" class="btn">在线咨询</a>
                        </div>
                    </div>
                </div>
            `;
            });

            container.innerHTML = allRoutesHtml;
        }

        document.addEventListener('DOMContentLoaded', async function() {
            // 加载旅游线路数据
            try {
                console.log('开始加载旅游线路数据...');
                
                // 加载一日游线路
                const oneDayRoutes = await TravelAPI.getTravelRoutesByType('oneday');
                console.log('一日游线路数据:', oneDayRoutes);
                renderRouteDetail(oneDayRoutes, 'oneday-routes');
                
                // 加载三日游线路
                const threeDayRoutes = await TravelAPI.getTravelRoutesByType('threedays');
                console.log('三日游线路数据:', threeDayRoutes);
                renderRouteDetail(threeDayRoutes, 'threeday-routes');
                
                // 加载五日游线路
                const fiveDayRoutes = await TravelAPI.getTravelRoutesByType('fivedays');
                console.log('五日游线路数据:', fiveDayRoutes);
                renderRouteDetail(fiveDayRoutes, 'fiveday-routes');
                
            } catch (error) {
                console.error('加载旅游线路数据时发生错误:', error);
                // 显示错误信息
                ['oneday-routes', 'threeday-routes', 'fiveday-routes'].forEach(containerId => {
                    const container = document.getElementById(containerId);
                    if (container) {
                        container.innerHTML = `
                            <div class="api-error">
                                <i class="fas fa-exclamation-triangle"></i>
                                加载旅游线路数据失败
                            </div>
                        `;
                    }
                });
            }
        });

        // 平滑滚动代码保持不变
        document.addEventListener('DOMContentLoaded', function() {
            // 获取所有锚点链接
            const anchorLinks = document.querySelectorAll('a[href^="#"]');
            
            // 为每个锚点链接添加点击事件
            anchorLinks.forEach(function(link) {
                link.addEventListener('click', function(e) {
                    e.preventDefault();
                    
                    // 获取目标元素的ID
                    const targetId = this.getAttribute('href');
                    
                    // 如果是空锚点或者页面顶部，直接滚动到顶部
                    if (targetId === '#' || targetId === '') {
                        window.scrollTo({
                            top: 0,
                            behavior: 'smooth'
                        });
                        return;
                    }
                    
                    // 获取目标元素
                    const targetElement = document.querySelector(targetId);
                    
                    // 如果目标元素存在，滚动到该元素
                    if (targetElement) {
                        // 获取元素的位置
                        const elementPosition = targetElement.getBoundingClientRect().top;
                        const offsetPosition = elementPosition + window.pageYOffset - 100; // 减去100px的偏移量，避免被导航栏遮挡
                        
                        // 平滑滚动到目标位置
                        window.scrollTo({
                            top: offsetPosition,
                            behavior: 'smooth'
                        });
                    }
                });
            });
        });
    </script>
</body>
</html> 